<?php

namespace addon\ly_shareholder\app\model;

use core\base\BaseModel;

/**
 * 股东等级
 */
class ShareholderLevel extends BaseModel
{


    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'level_id';

    /**
     * 模型名称
     * @var string
     */
    protected $name = 'ly_shareholder_level';


    /**
     * 等级升级说明
     * @param $value
     * @param $data
     * @return mixed|string
     */
    public function getLevelTextAttr($value, $data)
    {
        $condition = [];
        if($data['upgrade_type'] == 0) {
            $condition['text'] = '或';
        }else{
            $condition['text'] = '且';
        }
        $list = [];

        if($data['order_num'] > 0) {
            $list[] = '自购订单总数大于等于'.$data['order_num'];
        }
        if($data['order_money'] > 0) {
            $list[] = '自购订单总额大于等于'.$data['order_money'];
        }
        if($data['recharge_money'] > 0) {
            $list[] = '充值金额大于等于'.$data['recharge_money'];
        }
        if($data['order_goods_id'] != '') {
            $list[] = '购买指定商品';
        }
        if($data['child_num'] > 0) {
            $list[] = '一级下线人数大于等于'.$data['child_num'];
        }
        if($data['child2_num'] > 0) {
            $list[] = '二级下线人数大于等于'.$data['child2_num'];
        }
        //直推某个等级人数大于等于,json格式，level_id,level_num
        if($data['child_level_num'] != '') {
            $child_level_num = json_decode($data['child_level_num'], true);
            foreach($child_level_num as $item) {
                $list[] = '直推'.$item['level_id'].'级人数大于等于'.$item['level_num'];
            }
        }

        $condition['list'] = $list;
        return $condition;

    }
}
